package com.shuoyue.ycgk.ui.questionbank.practice.specialtraining.questionitem;

import android.content.Context;
import android.content.Intent;

import com.shuoyue.ycgk.entity.QuestionParent;
import com.shuoyue.ycgk.entity.UploadEstimateSucInfo;
import com.shuoyue.ycgk.entity.UserAnswerPager;
import com.shuoyue.ycgk.entity.UserTestPaper;
import com.shuoyue.ycgk.ui.questionbank.QuestionUtil;
import com.shuoyue.ycgk.ui.questionbank.UploadAnswerContract;
import com.shuoyue.ycgk.ui.questionbank.UserPaperQuestionContract;
import com.shuoyue.ycgk.ui.questionbank.base.BaseQuestionActivity;
import com.shuoyue.ycgk.ui.questionbank.practice.specialtraining.QuestionSpecialCountActivity;
import com.shuoyue.ycgk.views.dialog.common.HintConfirmDialog;

import java.util.ArrayList;
import java.util.List;

public class SpeciaDoingActivity
        extends BaseQuestionActivity
        implements UserPaperQuestionContract.View, UploadAnswerContract.View {
    UserTestPaper userpaper;
    String pagerName;

    UserPaperQuestionContract.Presenter spePresenter;
    UploadAnswerContract.Presenter anserPresenter;

    public static void start(Context source,
                             UserTestPaper pager,
                             String name,
                             ArrayList<QuestionParent> questionParents) {
        source.startActivity(new Intent(source, SpeciaDoingActivity.class)
                .putExtra("pager", pager)
                .putExtra("epName", name)
                .putExtra("questions", questionParents)
        );
    }

    @Override
    protected void initView() {
        super.initView();
        userpaper = (UserTestPaper) getIntent().getSerializableExtra("pager");
        pagerName = getIntent().getStringExtra("epName");
        name.setText(pagerName);
    }

    @Override
    public Class getClassT() {
        return SpecialDoingMateralFragment.class;
    }

    @Override
    public Class getClassK() {
        return SpecialDoingSimpleFragment.class;
    }

    @Override
    public void initData() {
        super.initData();

        spePresenter = new UserPaperQuestionContract.Presenter();
        spePresenter.attachView(this);
        anserPresenter = new UploadAnswerContract.Presenter();
        anserPresenter.attachView(this);
        spePresenter.getQuestions(userpaper.getMemberTestPaperId(), 1, userpaper.getType());
    }

    @Override
    public void lastOne() {
        QuestionSpecialCountActivity.start(mContext, userpaper, pagerName,
                (ArrayList<QuestionParent>) questionParents);
        super.finish();
    }

    @Override
    public void back() {
        finish();
    }


    @Override
    public void setQuestions(List<QuestionParent> userpaper) {
        setThisActData(userpaper);
    }

    @Override
    public void finish() {
        HintConfirmDialog hintConfirmDialog = new HintConfirmDialog(mContext,
                "提示",
                "是否退出");
        hintConfirmDialog.setOkListener(v -> {
            UserAnswerPager userAnswerPager = QuestionUtil.getUserAnswerPager(questionParents, userpaper.getMemberTestPaperId(), userpaper.getType());
            if (userAnswerPager == null) {
                super.finish();
            } else {
                anserPresenter.uploadAnswerNoView(userAnswerPager,  1, true);
                super.finish();
            }

        });
        hintConfirmDialog.show();
    }

    @Override
    public void uploadSuc(boolean isNext) {
        super.finish();
    }

    @Override
    public void uploadEstimatteSuc(boolean b, UploadEstimateSucInfo uploadEstimateSucInfo, int submit) {

    }

    @Override
    public void uploadFail(boolean isNext, int submit) {

    }
}
